const express=require("express")
const req = require("express/lib/request")
const router=express.Router()
const bokeServ=require("../../services/homeget")

const {
    asyncHandler
}=require("../getSendResult")

router.get("/",asyncHandler(async(req,res,next)=>{
    console.log(req.query)
    const page=req.query.page||1;
    const limit=req.query.limit||4;
    return await bokeServ.getfenye(page,limit);
}))

router.get("/getfindbk",(async(req,res)=>{
    const page=req.query.page|1;
    const limit=req.query.limit||1;
    const id=req.query.id
    const obj=await bokeServ.getIdfind(page,limit,id);
    return res.send(`
    <!DOCTYPE html>
    <html lang="en-US">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Katen - Minimal Blog & Magazine HTML Theme</title>
        <meta name="description" content="Katen - Minimal Blog & Magazine HTML Theme">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
        <link rel="stylesheet" href="http://localhost:3300/css/bootstrap.min.css" type="text/css" media="all">
        <link rel="stylesheet" href="http://localhost:3300/css/simple-line-icons.css" type="text/css" media="all">
        <link rel="stylesheet" href="http://localhost:3300/css/style.css" type="text/css" media="all">
    
    </head>
    
    <body>
    
    <!-- preloader -->
    <div id="preloader">
        <div class="book">
            <div class="inner">
                <div class="left"></div>
                <div class="middle"></div>
                <div class="right"></div>
            </div>
            <ul>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
    </div>
    
    <!-- site wrapper -->
    <div class="site-wrapper">
    
        <div class="main-overlay"></div>
    
        <!-- header -->
        <header class="header-default">
		<nav class="navbar navbar-expand-lg">
			<div class="container-xl">
				<!-- site logo -->
				<a class="navbar-brand">
					<img src="http://localhost:3300/images/loo.jfif" alt="logo" class="toux"/>
					<i class="icon-close close"></i>
				</a> 

				<div class="collapse navbar-collapse">
					<!-- menus -->
					<ul class="navbar-nav mr-auto">
						<li class="nav-item dropdown active">
							<a class="nav-link dropdown-toggle" href="http://localhost:3300/index.html">HOME</a>
							<ul class="dropdown-menu">
								<li><a class="dropdown-item" href="http://localhost:3300/index.html">首页</a></li>
								<li><a class="dropdown-item">博客人生</a></li>
								<li><a class="dropdown-item" href="http://localhost:3300/classic.html">心情说说</a></li>
								<li><a class="dropdown-item" href="http://localhost:3300/liuyan.html">留言</a></li>
								<li><a class="dropdown-item" href="http://localhost:3300/contact.html">登陆/注册</a></li>
							</ul>
						</li>
						<li class="nav-item">
							<a class="nav-link">博客人生</a>
						</li>
						<li class="nav-item">
							<a class="nav-link" href="http://localhost:3300/classic.html">心情说说</a>
						</li>
						<li class="nav-item dropdown">
							<a class="nav-link dropdown-toggle" href="http://localhost:3300/about.html">关于我</a>
							<ul class="dropdown-menu">
								<li><a class="dropdown-item">myself1</a></li>
								<li><a class="dropdown-item">myself1</a></li>
								<li><a class="dropdown-item">myself1</a></li>
							</ul>
						</li>
						<li class="nav-item">
							<a class="nav-link" href="http://localhost:3300/contact.html">登录/注册</a>
						</li>
					</ul>
				</div>

				<!-- header right section -->
				<div class="header-right">
					<!-- social icons -->
					<ul class="social-icons list-unstyled list-inline mb-0">
						<li class="list-inline-item"><a href="#"><i class="fab fa-facebook-f"></i></a></li>
						<li class="list-inline-item"><a href="#"><i class="fab fa-twitter"></i></a></li>
						<li class="list-inline-item"><a href="#"><i class="fab fa-instagram"></i></a></li>
						<li class="list-inline-item"><a href="#"><i class="fab fa-pinterest"></i></a></li>
						<li class="list-inline-item"><a href="#"><i class="fab fa-medium"></i></a></li>
						<li class="list-inline-item"><a href="#"><i class="fab fa-youtube"></i></a></li>
					</ul>
					<!-- header buttons -->
					<div class="header-buttons">
						<button class="search icon-button">
							<i class="icon-magnifier"></i>
						</button>
						<button class="burger-menu icon-button">
							<span class="burger-icon"></span>
						</button>
					</div>
				</div>
			</div>
		</nav>
	</header>
    
        <!-- section main content -->
        <section class="main-content mt-3">
            <div class="container-xl">
    
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item"><a href="#">详细</a></li>
                        <li class="breadcrumb-item active" aria-current="page">id:${obj.rows[0].id}</li>
                    </ol>
                </nav>
    
                <div class="row gy-4">
    
                    <div class="col-lg-8">
                        <!-- post single -->
                        <div class="post post-single">
                            <!-- post header -->
                            <div class="post-header">
                                <h1 class="title mt-0 mb-3">${obj.rows[0].name}</h1>
                                <ul class="meta list-inline mb-0">
                                    <li class="list-inline-item"><a href="#"><img src="http://localhost:3300/images/other/author-sm.png" class="author" alt="author"/>Han Yu</a></li>
                                    <li class="list-inline-item"><a href="#" id="hoot">${obj.rows[0].hot}</a>阅读</li>
                                    <li class="list-inline-item">${obj.rows[0].createdAt.slice(0,10)}</li>
                                </ul>
                            </div>
                            <!-- featured image -->
                            <div class="featured-image">
                                <img src="http://localhost:3300/images/posts/featured-lg.jpg" alt="post-title" />
                            </div>
                            <!-- post content -->
                            <div class="post-content clearfix" id="editor">
                                ${obj.rows[0].txt}
                            </div>
                            <!-- post bottom section -->
                            <div class="post-bottom">
                                <div class="row d-flex align-items-center">
                                    <div class="col-md-6 col-12 text-center text-md-start">
                                        <!-- tags -->
                                        <a href="#" class="tag">#标签一</a>
                                        <a href="#" class="tag">#标签二</a>
                                        <a href="#" class="tag">#标签三</a>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <!-- social icons -->
                                    </div>
                                </div>
                            </div>
    
                        </div>
    
                        <div class="spacer" data-height="50"></div>
    
                        <div class="about-author padding-30 rounded">
                            <div class="thumb">
                                <img src="http://localhost:3300/images/tx.jpeg" style="height:100px;width:100px"/>
                            </div>
                            <div class="details">
                                <h4 class="name"><a href="#">Han Yu</a></h4>
                                <p>你好，对文章有疑问或想法请在下方评论</p>
                                <!-- social icons -->
                            </div>
                        </div>
    
                        <div class="spacer" data-height="50"></div>
    
                        <!-- section header -->
                        <div class="section-header">
                            <h3 class="section-title h3pl">评论 ()</h3>
                            <img src="http://localhost:3300/images/wave.svg" class="wave" alt="wave" />
                        </div>
                        <!-- post comments -->
                        <div class="comments bordered padding-30 rounded">
    
                            <ul class="comments tll">
                                <!-- comment item -->
                                
                                <!-- comment item -->
                                
                                <!-- comment item -->
                                
                            </ul>
                        </div>
    
                        <div class="spacer" data-height="50"></div>
    
                        <!-- section header -->
                        <div class="section-header">
                            <h3 class="section-title">发表评论</h3>
                            <img src="http://localhost:3300/images/wave.svg" class="wave" alt="wave" />
                        </div>
                        <!-- comment form -->
                        <div class="comment-form rounded bordered padding-30">
    
                            <form id="comment-form" class="comment-form" method="post">
                    
                                <div class="messages"></div>
                                
                                <div class="row">
    
                                    <div class="column col-md-12">
                                        <!-- Comment textarea -->
                                        <div class="form-group">
                                            <textarea name="InputComment" id="InputComment" class="txt form-control" rows="4" placeholder="说点什么吧..." required="required"></textarea>
                                        </div>
                                    </div>
                            
                                </div>
        
                                <button type="submit" name="submit" id="submit" value="Submit" class="fb btn btn-default">发布</button>
        
                            </form>
                        </div>
                    </div>
    
                    <div class="col-lg-4">
					<!-- sidebar -->
					<div class="sidebar">
						<!-- widget about -->
						<div class="widget rounded">
							<div class="widget-about data-bg-image text-center" data-bg-image="http://localhost:3300/images/map-bg.png">
								<p class="mb-4">你好,欢迎来到我的博客,浏览过程中遇到任何bug和不愉快的用户体验请前往留言区告诉博主,博主会及时修正与优化(●'◡'●)</p>
							</div>
						</div>
						<!-- widget popular posts -->
						<div class="widget rounded">
							<div class="widget-header text-center">
								<h3 class="widget-title">热门帖子</h3>
								<img src="http://localhost:3300/images/wave.svg" class="wave" alt="wave" />
							</div>
							<div class="widget-content">
								<!-- post -->
								<div class="post post-list-sm circle">
									<div class="thumb circle">
										<span class="number">1</span>
										<a>
											<div class="inner">
												<img src="http://localhost:3300/images/posts/tabs-1.jpg" alt="post-title" />
											</div>
										</a>
									</div>
									<div class="details clearfix">
										<h6 class="post-title my-0"><a id="hot1"></a></h6>
										<ul class="meta list-inline mt-1 mb-0">
											<li class="list-inline-item"></li>
										</ul>
									</div>
								</div>
								<!-- post -->
								<div class="post post-list-sm circle">
									<div class="thumb circle">
										<span class="number">2</span>
										<a>
											<div class="inner">
												<img src="http://localhost:3300/images/posts/tabs-2.jpg" alt="post-title" />
											</div>
										</a>
									</div>
									<div class="details clearfix">
										<h6 class="post-title my-0"><a id="hot2"></a></h6>
										<ul class="meta list-inline mt-1 mb-0">
											<li class="list-inline-item"></li>
										</ul>
									</div>
								</div>
								<!-- post -->
								<div class="post post-list-sm circle">
									<div class="thumb circle">
										<span class="number">3</span>
										<a>
											<div class="inner">
												<img src="http://localhost:3300/images/posts/tabs-3.jpg" alt="post-title" />
											</div>
										</a>
									</div>
									<div class="details clearfix">
										<h6 class="post-title my-0"><a id="hot3"></a></h6>
										<ul class="meta list-inline mt-1 mb-0">
											<li class="list-inline-item"></li>
										</ul>
									</div>
								</div>
							</div>		
						</div>
						<!-- widget categories -->
						<div class="widget rounded">
							<div class="widget-header text-center">
								<h3 class="widget-title">探索主题</h3>
								<img src="http://localhost:3300/images/wave.svg" class="wave" alt="wave" />
							</div>
							<div class="widget-content">
								<ul class="list">
									<li><a href="#">生活方式</a><span>(5)</span></li>
									<li><a href="#">灵感</a><span>(2)</span></li>
									<li><a href="#">时尚</a><span>(4)</span></li>
									<li><a href="#">生活趣事</a><span>(1)</span></li>
									<li><a href="#">人生目标</a><span>(7)</span></li>
									<li><a href="#">情感分享</a><span>(3)</span></li>
								</ul>
							</div>
							
						</div>
					</div>
				</div>
    
                </div>
    
            </div>
        </section>
    
        <!-- instagram feed -->
        <div class="instagram">
		<div class="container-xl">
			<!-- button -->
			<a href="#" class="btn btn-default btn-instagram">849136764@qq.com</a>
			<!-- images -->
			<div class="instagram-feed d-flex flex-wrap">
				<div class="insta-item col-sm-2 col-6 col-md-2">
					<a href="#">
						<img src="http://localhost:3300/images/insta/insta-1.jpg" alt="insta-title" />
					</a>
				</div>
				<div class="insta-item col-sm-2 col-6 col-md-2">
					<a href="#">
						<img src="http://localhost:3300/images/insta/insta-2.jpg" alt="insta-title" />
					</a>
				</div>
				<div class="insta-item col-sm-2 col-6 col-md-2">
					<a href="#">
						<img src="http://localhost:3300/images/insta/insta-3.jpg" alt="insta-title" />
					</a>
				</div>
				<div class="insta-item col-sm-2 col-6 col-md-2">
					<a href="#">
						<img src="http://localhost:3300/images/insta/insta-4.jpg" alt="insta-title" />
					</a>
				</div>
				<div class="insta-item col-sm-2 col-6 col-md-2">
					<a href="#">
						<img src="http://localhost:3300/images/insta/insta-5.jpg" alt="insta-title" />
					</a>
				</div>
				<div class="insta-item col-sm-2 col-6 col-md-2">
					<a href="#">
						<img src="http://localhost:3300/images/insta/insta-6.jpg" alt="insta-title" />
					</a>
				</div>
			</div>
		</div>
	</div>
    
        <!-- footer -->
        <footer>
		<div class="container-xl">
			<div class="footer-inner">
				<div class="row d-flex align-items-center gy-4">
					<!-- copyright text -->
					<div class="col-md-4">
						<span class="copyright">© 2022 HanYu. Template by ThemeGer.</span>
					</div>

					<!-- social icons -->
					<div class="col-md-4 text-center">
						
					</div>

					<!-- go to top button -->
					<div class="col-md-4">
						<a href="#" id="return-to-top" class="float-md-end"><i class="icon-arrow-up"></i>Back to Top</a>
					</div>
				</div>
			</div>
		</div>
	</footer>
    
    </div><!-- end site wrapper -->
    
    <!-- search popup area -->
    <div class="search-popup">
        <!-- close button -->
        <button type="button" class="btn-close" aria-label="Close"></button>
        <!-- content -->
        <div class="search-content">
            <div class="text-center">
                <h3 class="mb-4 mt-0">Press ESC to close</h3>
            </div>
            <!-- form -->
            <form class="d-flex search-form">
                <input class="form-control me-2" type="search" placeholder="Search and press enter ..." aria-label="Search">
                <button class="btn btn-default btn-lg" type="submit"><i class="icon-magnifier"></i></button>
            </form>
        </div>
    </div>
    
    <!-- canvas menu -->
    <div class="canvas-menu d-flex align-items-end flex-column" style="overflow-y:hidden;">
	<!-- close button -->
	<button type="button" class="btn-close" aria-label="Close"></button>

	<!-- logo -->
	<div class="logo">
		<a class="navbar-brand">
			<img src="http://localhost:3300/images/loo.jfif" alt="logo" id="toux" class="toux"/>
			<button class="btn btn-default close" style="margin: 10px 45px 0;display: none;">退出登录</button>
		</a> 
	</div>

	<!-- menu -->
	<nav>
		<ul class="vertical-menu">
			<li class="active">
				<a href="http://localhost:3300/index.html">Home</a>
				<ul class="submenu">
					<li><a href="http://localhost:3300/index.html">首页</a></li>
					<li><a>博客人生</a></li>
					<li><a href="http://localhost:3300/classic.html">心情说说</a></li>
					<li><a href="http://localhost:3300/minimal.html">留言</a></li>
					<li><a href="http://localhost:3300/contact.html">登陆/注册</a></li>
				</ul>
			</li>
			<li><a>博客人生</a></li>
			<li><a href="http://localhost:3300/classic.html">心情说说</a></li>
			<li>
				<a href="#">关于我</a>
				<ul class="http://localhost:3300/submenu">
					<li><a>Myself1</a></li>
					<li><a>Myself2</a></li>
					<li><a>Myself3</a></li>
				</ul>
			</li>
			<li><a href="http://localhost:3300/contact.html">登录/注册</a></li>
		</ul>
	</nav>

	<!-- social icons -->
	<ul class="social-icons list-unstyled list-inline mb-0 mt-auto w-100">
		<li class="list-inline-item"><a href="#"><i class="fab fa-facebook-f"></i></a></li>
		<li class="list-inline-item"><a href="#"><i class="fab fa-twitter"></i></a></li>
		<li class="list-inline-item"><a href="#"><i class="fab fa-instagram"></i></a></li>
		<li class="list-inline-item"><a href="#"><i class="fab fa-pinterest"></i></a></li>
		<li class="list-inline-item"><a href="#"><i class="fab fa-medium"></i></a></li>
		<li class="list-inline-item"><a href="#"><i class="fab fa-youtube"></i></a></li>
	</ul>
</div>
    
    <!-- JAVA SCRIPTS -->
    <script src="http://localhost:3300/js/jquery.min.js"></script>
	<script src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>
    <script src="http://localhost:3300/js/public.js"></script>
    <script src="http://localhost:3300/js/popper.min.js"></script>
    <script src="http://localhost:3300/js/bootstrap.min.js"></script>
    <script src="http://localhost:3300/js/slick.min.js"></script>
    <script src="http://localhost:3300/js/jquery.sticky-sidebar.min.js"></script>
    <script src="http://localhost:3300/js/custom.js"></script>
    <script src="http://localhost:3300/js/xx.js"></script>
	<script src="http://localhost:3300/js/hot.js"></script>
	<script>
	const E = window.wangEditor
	const editor = new E( document.getElementById('editor') )
	editor.config.height = 1800
	// editor.config.uploadImgServer = '/api/upload';
	editor.config.uploadFileName = 'img';
	editor.config.uploadImgHooks = {
        customInsert: function(insertImgFn, result) {
        // insertImgFn 可把图片插入到编辑器，传入图片 src ，执行函数即可
		insertImgFn(result.data.originurl)
		}
	}
	editor.create()		
	</script>
    </body>
    </html>
    `);
})
)

router.get("/getdz",asyncHandler(async(req,res,next)=>{
    const page=req.query.page|1;
    const limit=req.query.limit||1;
    const id=req.query.id
    return await bokeServ.getIdfind(page,limit,id);
}))

router.get("/getmh",asyncHandler(async(req,res,next)=>{
	const page=req.query.page|1;
    const limit=req.query.limit||4;
	const name = req.query.name
	return await bokeServ.getMhfind(page,limit,name);
}))

router.get("/gethot",asyncHandler(async(req,res,next)=>{
	const page=req.query.page||1;
    const limit=req.query.limit||3;
	return await bokeServ.getHot(page,limit)
}))

router.get("/updatebk",asyncHandler(async(req,res,next)=>{
    console.log(req.query)
    const id=req.query.id
    const obj={
        dz:req.query.dz
    }
    return await bokeServ.updateBoke(id,obj)
}))

router.post("/updateHot",asyncHandler(async(req,res,next)=>{
	const id=req.body.id
	return await bokeServ.updateHot(id,{
		hot:req.body.hot
	 })
}))

router.get("/getfl",asyncHandler(async(req,res,next)=>{
	const page=req.query.page|1;
    const limit=req.query.limit||10;
	const lx = req.query.lx;
	return await bokeServ.getFl(page,limit,lx);
}))

router.post("/addbk",asyncHandler(async(req,res,next)=>{
	console.log(req.body)
    return await bokeServ.addBk(req.body)
}))

module.exports = router